package swordoffer.offer10;

public class FibBestSolution {
    public static void main(String[] args) {
        fib(3);
    }
    public int fibExtra(int n) {
        if(n < 2){
            return n;
        }
        int[] dp = new int[n + 1];
        dp[0] = 0;
        dp[1] = 1;
        for (int i = 2; i < dp.length; i++) {
            dp[i] = (dp[i - 2] + dp[i - 1]) % 1000000007;
        }
        return dp[n] % 1000000007;
    }
    public static int fib(int n) {
        int a = 0;
        int b = 1;
        int sum = 0;
        for (int i = 0; i < n; i++){
            sum = (a + b) % 1000000007;
            a = b;
            b = sum;
        }
        //为什么是return a ？ 循环从0开始， 到 n - 1结束。
        //循环一次，a就代表fib(1)，循环2次，a代表fib(2)
        return a;
    }
}
